package com.example.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class XTokenRequestInterceptor implements RequestInterceptor {
    /**
     * 请求拦截器模板
     * 两种生效方式：
     * 1、在yml中配置
     * 2、注入容器，openfeign会在远程调用的时候调用RequestInterceptor
     * @param requestTemplate
     */
    @Override
    public void apply(RequestTemplate requestTemplate) {
        System.out.println("XTokenRequestInterceptor");
        requestTemplate.header("X-Token", UUID.randomUUID().toString());
    }
}
